//
//  Mu_BaseTableViewController.m
//  NewMarryU
//
//  Created by Cedar on 2018/7/11.
//  Copyright © 2018年 Cedar. All rights reserved.
//

#import "M1BaseTableViewController.h"

@interface M1BaseTableViewController ()

@end

@implementation M1BaseTableViewController

- (void)loadView{
    [super loadView];
    //tableView 基本初始化

    if (!self.m1_tableView) {
        self.m1_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT - STATUS_HEIGHT - 44) style:self.m1_tableStyle];
        self.m1_tableView.rowHeight = UITableViewAutomaticDimension;
        self.m1_tableView.estimatedRowHeight = 50;
        self.m1_tableView.dataSource = self;
        self.m1_tableView.delegate = self;
        self.m1_tableView.estimatedSectionFooterHeight = 0;
        self.m1_tableView.estimatedSectionHeaderHeight = 0;
        self.m1_tableView.showsVerticalScrollIndicator = NO;
        self.m1_tableView.showsHorizontalScrollIndicator = NO;
        [self.view addSubview:self.m1_tableView];

        self.m1_tableView.keyboardDismissMode          = UIScrollViewKeyboardDismissModeOnDrag;
        
        if (@available(iOS 11.0, *))
        {
            self.m1_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
    }
    if (!self.m1_showSeparator) {
        self.m1_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    } else {
        self.m1_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    }
}

-(id)initWithStyle:(UITableViewStyle)style{
    self = [super init];
    if (self) {
        self.m1_showSeparator = NO;
        self.m1_tableStyle = style;
    }
    return self;
}

-(id)init{
    self = [super init];
    if (self) {
        self.m1_showSeparator = NO;
        self.m1_tableStyle = UITableViewStylePlain;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.m1_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(UIEdgeInsetsMake(m1_NAV_HEIGHT, 0, 0, 0));
    }];
}

- (NSMutableArray *)m1_listData{
    if(!_m1_listData){
        _m1_listData = [NSMutableArray array];
    }
    return _m1_listData;
}

#pragma mark - tableView datasource && tableView delegate
//常规表格的数据和委托

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 0;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * LOAD_MORE_CELL = @"LOAD_MORE_CELL_IDENTIFITY";
    
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:LOAD_MORE_CELL];
    
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:LOAD_MORE_CELL];
    }
    return cell;
}

- (void) m1_createRightBarButtonItem:(NSString *)title titleColor:(UIColor *)color action:(SEL)action{
    CGFloat width;
    if ([title length] > 2) {
        width = 70;
    }else{
        width = 40;
    }
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, width, 44);
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:color forState:UIControlStateNormal];
    button.titleLabel.font = m1_font(16);
    [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * rightBtn = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = rightBtn;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
